package cn.kgc.crowdfundingadmin2.controller;

import cn.kgc.crowdfundingadmin2.common.ResultEntity;
import cn.kgc.crowdfundingadmin2.pojo.Auth;
import cn.kgc.crowdfundingadmin2.service.AuthService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class AuthController {
    @Resource
    AuthService authService;

    @ResponseBody
    @RequestMapping("/assign/get/all/auth")
    public ResultEntity<List<Auth>> getAllAuth(){
        List<Auth> allAuth = authService.getAllAuth();
        return ResultEntity.successWithoutData(allAuth);
    }

    @ResponseBody
    @RequestMapping("/assign/get/assigned/auth/id/list")
    public ResultEntity<List<Integer>> authIdList(Integer roleId){
        List<Integer> list = authService.getAssignedAuthIdList(roleId);
        return ResultEntity.successWithoutData(list);
    }

    @ResponseBody
    @RequestMapping("/assign/do/assign")
    public ResultEntity<String> doAssign(@RequestBody Map<String,List<Integer>> assignDataMap){
        authService.updateRelationShipBetweenRoleAndAuth(assignDataMap);
        return ResultEntity.successWithoutData();
    }
}
